/*
 * Copyright (c) 18/5/25 . All Rights Reserved.
 */
package com.cgmnx.admin.web.converter.entity;

import com.cgmnx.admin.dao.condition.ReplyCondition;
import com.cgmnx.admin.model.enums.ReplyAuditStatus;
import com.cgmnx.admin.web.converter.Convert;
import com.cgmnx.admin.web.model.param.ReplyQueryParam;
import com.google.common.base.Strings;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;

/**
 * @author: z Date: 18/5/25 Time: 下午5:09
 * @version: 1.0.0
 */
@Component
public class ReplyConditionConverter implements Convert<ReplyQueryParam, ReplyCondition> {
    @Override
    public ReplyCondition convert(ReplyQueryParam t) {
        ReplyCondition replyCondition = new ReplyCondition();
        if (t != null) {
            if (!Strings.isNullOrEmpty(t.getUserName()))
                replyCondition.setUserName(t.getUserName());
            if (!Strings.isNullOrEmpty(t.getEndDate())) {
                replyCondition.setEndDate(Timestamp.valueOf(t.getEndDate()));
            }
            if (!Strings.isNullOrEmpty(t.getStartDate())) {
                replyCondition.setStartDate(Timestamp.valueOf(t.getStartDate()));
            }
            if (t.getId() > 1) {
                replyCondition.setId(t.getId());
            }
            if (t.getStatus() >= 0) {
                replyCondition.setStatus(ReplyAuditStatus.codeOf(t.getStatus()));
            }
        }

        return replyCondition;

    }

    @Override
    public List<ReplyCondition> convert(List<ReplyQueryParam> t) {
        throw new UnsupportedOperationException();
    }
}
